<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "swf_area".
 *
 * @property integer $id
 * @property integer $parent_id
 * @property string $name
 * @property integer $sort
 *
 * @property TbUser[] $tbUsers
 */
class SwfArea extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'swf_area';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['parentid', 'sort'], 'integer'],
            [['name'], 'required'],
            [['name'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'parentid' => Yii::t('app', 'Parentid'),
            'name' => Yii::t('app', 'Name'),
            'sort' => Yii::t('app', 'Sort'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTbUsers()
    {
        return $this->hasMany(TbUser::className(), ['regcity' => 'id']);
    }

    public static function selectCityAll(){
        $sql=self::find()->where(['parentid'=>0])->all();
        return $sql;
    }

    /**
     * 根据省级id来查询市级数据
     * @param $selectcityparent_id
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function selectCityParent_id($selectcityparent_id){
        $selectcityparent_id_all=self::find()->where(['parentid'=>$selectcityparent_id])->asArray()->all();
        return $selectcityparent_id_all;
    }
    /**
     * 根据省级id来查询市级数据
     * @param $selectcityparent_id
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function selectCityId($id,$parent_id){
        $selectcityid=self::find()->where(['id'=>$id])->asArray()->one();
        $selcetcityparentid=self::find()->where(['id'=>$parent_id,'parentid'=>$id])->asArray()->one();
        $arr=array($selectcityid,$selcetcityparentid);
        return $arr;
    }
}